#!/bin/bash
	#name=`date +%F-%R`
	cat *_unresolved_src_rpm_log | grep "Source" > unresolved_src_rpmlist_bak
	cat unresolved_src_rpmlist_bak | awk -F ':' '{print $2}' > unresolved_src_rpmlist_bak2
	sed -i '1,2d' unresolved_src_rpmlist_bak2
	cat unresolved_src_rpmlist_bak2 | while read line
	do
		if [[ ${line} =~ "(" ]];then
			echo "${line}" >> unresolved_src_rpmlist_bak3
			continue
		fi
		echo ${line%%-[0-9]*} >> unresolved_src_rpmlist_bak3
	done
	sort unresolved_src_rpmlist_bak3 | uniq > unresolved_src_rpmlist
	rm -f unresolved_src_rpmlist_bak*

	printf "# Project\t\t\t\t\t# Package\n" > resluts
	cat unresolved_src_rpmlist | while read pkg
	do
		osc search ${pkg} | grep -v "home" | grep -v "Project" | grep -v "No matches found for" >> resluts_bak
		sed '/^$/d' resluts_bak
		if [[ ! -s resluts_bak ]];then
			printf "None\t\t\t\t\t\t${pkg}\n" >> resluts
		else
			cat resluts_bak | grep -E "Mainline|20.09|Factory|bringInRely|Epol" | grep -Ev "Bak|RISC-V|bringInRely:20.09" >> resluts
		fi
		rm resluts_bak -f
	done	
	
	if false;then
	sed -i 's/^[ ]*//g' nothing_provides_log
	sed -i '1,2d' nothing_provides_log
	cat nothing_provides_log | while read line
	do
		if [[ ${line} =~ "package:" ]] &>/dev/null;then
			echo "${line% from*}" >> ${name}_unresolved_src_rpm_log
			continue
		fi
		dnf repoquery --whatprovides "${line}" > res
		wpname=$(cat res)
		# dnf repoquery --whatprovides return null
		if [ -z ${wpname} ] &>/dev/null;then
			echo "Source       : ${line}" >> ${name}_unresolved_src_rpm_log
		else
			#according binary pkgname to Find source pkgname
			dnf repoquery -i "${wpname%%-[0-9]*}" | grep Source | head -1 >> ${name}_unresolved_src_rpm_log
		fi
		rm -f res >/dev/null
	done
	rm -f nothing_provides_log &>/dev/null
	echo "You can see log in file ${name}_log and ${name}_src_pkglist and ${name}_unresolved_src_rpm_log"
	exit 0
	fi
